<?php
include_once("core/normal.php");
include_once("core/user.php");

/**
 * Users
 *
 * Class dealing with a group of Users (instances of ModelClass_User) 
 * 
 * @copyright inovia
 * @package oolime_core   
 */  
class SignupUsers extends Normal{

  /**
   * Retrieves the list of Users
   * @return $UsersNode the node containing all users
   */     
  public function getUsers() {
  	$UsersNode = $this->response->doc->createElement("users");
  	
  	$req       = "SELECT * FROM `user`;";
  	$result    = $this->database->queries($req);
  	
  	while($obj = $result->fetch_object()) {
      $UserNode = null;
      $tab = array(
        "id"=>"id",
        "pseudo" => "pseudo",
        "email"=>"email",
        "validated"=>"validated"
      );
      $user = mapObjectXML ($obj, "user", $tab);
      $UsersNode->appendChild($UserNode);
  	}
  	
    return $UsersNode;
  }
  
    /**
   * Retrieves a range of the list of Users
   * @return $UsersNode the node containing all users
   */     
  public function getUsersComplex($sql) {
  	$UsersNode = $this->response->doc->createElement("users");
  	
  	$req       = "SELECT * FROM `subscriptions` ".$sql.";";
  	$result    = $this->database->queries($req);
  	while($obj = $result->fetch_object()) {
  		$UserNode = null;
      $tab = array(
        "id"=>"id",
        "pseudo" => "pseudo",
        "email"=>"email",
        "validated"=>"validated"
      );
      $UserNode = $this->mapObjectXML ($obj, "user", $tab);
      
      
      $UserNode->appendChild($ActivationCodeNode);
      $UsersNode->appendChild($UserNode);
  	}
  	
    return $UsersNode;
  }
  
  public function getNumUsers($sql){
    $sqlCount = "SELECT COUNT(id) FROM `subscriptions` ".$sql;
    $result   = $this->database->queries($sqlCount);
    $array    = $result->fetch_array();
    
    return $array[0];
  }
}
?>
